package de.szut.sudoku.gui.menu;

import javax.swing.ButtonGroup;
import javax.swing.JMenu;
import javax.swing.JRadioButtonMenuItem;

import de.szut.sudoku.gui.LanguageContainer;
import de.szut.sudoku.gui.MainFrame;

/**
 * Sub menu for the language
 * 
 * @author dqi12huisinga
 * 
 */
@SuppressWarnings("serial")
public class OptionsLanguageSubMenu extends JMenu {
	public OptionsLanguageSubMenu() {
		// registers the submenu as translatable component
		MainFrame
				.getInstance()
				.getlContainer()
				.addTranslatableComponent("gui.menu.OptionsLanguageSubMenu",
						this);
		JRadioButtonMenuItem[] languages = new JRadioButtonMenuItem[LanguageContainer.languages.length];
		final ButtonGroup buttonGroup = new ButtonGroup();

		// generates the language buttons related to all available languages
		int index = 0;
		for (String currentLanguage : LanguageContainer.languages) {
			// generates the current button
			languages[index] = new JRadioButtonMenuItem(currentLanguage);
			languages[index].addItemListener(new LanguageListener());
			buttonGroup.add(languages[index]);
			// selects the button that is related to the current language
			if (currentLanguage.equals(MainFrame.getInstance().getlContainer()
					.getCurrentLanguage())) {
				languages[index].setSelected(true);
			}
			add(languages[index]);
			index++;
		}
	}
}
